# time.py
# Joshua Marshall Moore
# June 16th, 2010

# This Minute handles the representation of a minute on a Ubigraph
# It relies on a call to tick() => timekeeping is outside of this class

class Minute:
    def __init__(self, ubigraph):
        self.secondsVertices = []
        self.secondsEdges = []
        self.circle = False
        self.u = ubigraph

    def tick(self):
        l = len(self.secondsVertices)
        vertex = self.u.newVertex(label=str(l))
        self.secondsVertices.append(vertex)

    def setCircle(self, circle=True):
        if len(self.secondsVertices) <= 2:
            return
        if circle:
            l = len(self.secondsVertices)
            for i in range(0, l):
                e1 = self.secondsVertices[i]
                e2 = self.secondsVertices[(i+1)%l]
                edge = self.u.newEdge(e1, e2)
                self.secondsEdges.append(edge)
        if not circle:
            for edge in self.secondsEdges:
                edge.destroy()

    def setVisible(self, show=True):
        for edge in self.secondsEdges:
            edge.set(visible=show)
        for vertex in self.secondsVertices:
            vertex.set(visible=show)

    def isFull(self):
        if len(self.secondsVertices) is 60:
            return True
        return False
